package com.crm.Servlet;

import com.crm.Service.CustomerService;
import com.crm.Service.UserService;
import com.crm.ServiceImpl.CustomerServiceImpl;
import com.crm.ServiceImpl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @version : 1.0
 * @auther : hjx
 * @Date : 2021/6/29
 * @Description : 实训
 */
public class queryCnameServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html; charset=UTF-8");

        //查询所有的客户名字和ID，并输出给前端所属客户
        CustomerService customerService = new CustomerServiceImpl();
        List<String> customers = customerService.queryCname();
        req.setAttribute("cnames",customers);

        //查询所有用户名字和ID，并输出给前端所属负责人
        UserService userService = new UserServiceImpl();
        List<String> users = userService.queryUser();
        req.setAttribute("users",users);

        req.getRequestDispatcher("add.jsp").forward(req,resp);
    }


}

